<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="pos机编码">
              <el-input v-model="params.posCode" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <hospitalListbth :type="1" @childfun="childfun" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="6">
            <el-form-item label="地址" prop="province">
              <arealist @areafun="areafun" />
            </el-form-item>
          </el-col>-->
          <el-col :span="6">
            <el-form-item label="绑定时间" prop="province">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="pos机状态" prop="province">
              <el-select v-model="params.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
            <el-button style="margin-left:60px" type="primary" @click="dialogVisible = true">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        />
        <el-table-column prop="posCode" label="pos机编码" align="center" />
        <el-table-column prop="targetName" label="绑定医院" align="center" />
        <el-table-column prop="address" label="医院地址" align="center" />
        <el-table-column prop="targetId" label="医院id" align="center" />
        <el-table-column prop="bindTime" label="绑定时间" align="center" />
      </el-table>

      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="params.pageNum"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="params.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <el-dialog title="新增pos机" :visible.sync="dialogVisible" width="468px">
      <el-form :inline="true" label-width="80px" label-position="right">
        <el-form-item label="pos机编码">
          <el-input v-model="addparams.posCode" />
        </el-form-item>
        <el-form-item label="绑定医院">
          <hospitalListbth :type="2" @childfun="bindfun" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import postMessage from "@/api/postmanagement";
import arealist from "@/components/area";
import hospitalListbth from "@/components/hospitalList";
export default {
    name:"postmanagement",
  components: {
    hospitalListbth,
    arealist
  },
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      dialogVisible: false,
      options: [
        {
          value: "1",
          label: "已开启"
        },
        {
          value: "0",
          label: "已关闭"
        }
      ],
      time: "",
      tableData: [{}],
      total: 0,
      addparams: {
        hospitalId: "",
        posCode: ""
      },
      params: {
        posCode: "",
        targetId: "",
        bindStarTime: "",
        bindEndTime: "",
        status: "",
        address: "",
        pageNum: 1,
        pageSize: 20
      }
    };
  },
  watch: {
    time(val) {
      this.params.bindStarTime = val ? val[0] : "";
      this.params.bindEndTime = val ? val[1] : "";
    }
  },
  mounted() {
    this.list();
  },
  methods: {
    sure() {
      if (!this.addparams.hospitalId || !this.addparams.posCode) {
        this.$message.warning("请填写完整信息");
        return false;
      }
      postMessage.bingfun(this.addparams).then(res => {
        this.$message.warning(res.data.msg);
        if (res.data.code == 0) this.dialogVisible = false;
        this.list();
      });
    },
    list() {
      postMessage.list(this.params).then(res => {
        if (res.data.code == 0) {
          this.tableData = res.data.data.list;
          this.total = res.data.data.count;
        } else {
          this.$message.warning(res.data.msg);
        }
      });
    },
    searchfun() {
      this.params.pageNum = 1;
      this.list();
    },
    areafun(datas) {
      console.log(datas);
    },

    childfun(res) {
      this.params.targetId = res.id + "";
    },
    bindfun(res) {
      this.addparams.hospitalId = res.id;
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
